//
//  MemberChosenViewController.m
//  NOAHWM
//
//  Created by Ryan on 13-7-11.
//  Copyright (c) 2013年 Ryan. All rights reserved.
//

#import "MemberChosenViewController.h"
#import "NYMemberCenterDataManager.h"

@interface MemberChosenViewController ()

@end

@implementation MemberChosenViewController

@synthesize phoneCallAs;
@synthesize kefuButton;
@synthesize isFromLogin;

- (UIActionSheet *)phoneCallAs
{
    if(nil == phoneCallAs)
    {
        phoneCallAs = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"咨询客服", nil];
    }
    return phoneCallAs;
}

#pragma mark - IBAction methods
- (IBAction)kefuButtonClicked:(id)sender
{
    [self.phoneCallAs showInView:self.view];
}
- (IBAction)gerenButtonClicked:(id)sender
{
    //用户角色第一个是个人
    [NYMemberCenterDataManager sharedManager].loginMember = [[NYMemberCenterDataManager sharedManager].memberRoles objectAtIndex:0];
    //重新load左菜单
    [[NSNotificationCenter defaultCenter] postNotificationName:kUserChangeNotification object:nil];
    //修改有菜单中“申请认证”按钮状态
    [[NSNotificationCenter defaultCenter] postNotificationName:kRefreshApplyAuthNotificaiton object:nil];
    //重新获取个人信息
    [[NSNotificationCenter defaultCenter] postNotificationName:kRefreshPersonalInfoNotification object:nil];
    if(self.isFromLogin)
    {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
    else
    {
//        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (IBAction)jigouButtonClicked:(id)sender
{
    //用户第二个角色为机构
    [NYMemberCenterDataManager sharedManager].loginMember = [[NYMemberCenterDataManager sharedManager].memberRoles objectAtIndex:1];
    //重新load左菜单
    [[NSNotificationCenter defaultCenter] postNotificationName:kUserChangeNotification object:nil];
    //修改有菜单中“申请认证”按钮状态
    [[NSNotificationCenter defaultCenter] postNotificationName:kRefreshApplyAuthNotificaiton object:nil];
    //重新获取个人信息
    [[NSNotificationCenter defaultCenter] postNotificationName:kRefreshPersonalInfoNotification object:nil];
    if(self.isFromLogin)
        [self.navigationController dismissModalViewControllerAnimated:YES];
    else
    {
//        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - BaseViewController methods
- (void)leftItemTapped
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UIViewController methods
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNaviTitle:@"选择身份"];
    [self setLeftNaviItemWithTitle:nil imageName:@"Icon_Back"];
    [self setRightNaviItemWithTitle:nil imageName:nil];
    
    [self.kefuButton setTitle:[NSString stringWithFormat:@"客服热线：%@",[NYMemberCenterDataManager sharedManager].loginMember.custom_service_phone] forState:UIControlStateNormal];
    if(self.isFromLogin)
        [self addSwipePopGesture];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if(self.isViewLoaded && !self.view.window)
    {
        self.view = nil;
        self.kefuButton = nil;
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.kefuButton = nil;
}

- (void)dealloc
{
    [kefuButton release];
    [phoneCallAs release];
    [super dealloc];
}

#pragma mark - UIActionSheetDelegate methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[NYMemberCenterDataManager sharedManager].loginMember.custom_service_phone]]];
    }
}

@end
